package com.sz.job;

import com.alibaba.fastjson.JSON;
import com.sz.controller.TransferController;
import com.sz.mapper.TUserMapper;
import com.sz.model.Result;
import com.sz.model.TDealParticulars;
import com.sz.mapper.TUserMapper;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Calendar;

/**
 * @version 0.1
 * @auth admin.
 * @time 2018/5/27 16:36
 * @since 0.1
 */
public class MyJob extends QuartzJobBean {

    @Autowired
    private TUserMapper tUserMapper;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private TransferController transferController;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {

        Calendar calendar = Calendar.getInstance();
        //System.out.println("用户信息--"+tUserMapper.selectAll());

        String tDealParticulars = stringRedisTemplate.opsForValue().get("tDealParticulars");

        if(tDealParticulars!=null&&tDealParticulars!=""){
            TDealParticulars tDealParticulars2 = JSON.parseObject(tDealParticulars, TDealParticulars.class);

            Result insertSealP = transferController.getInsertSealP(tDealParticulars2);
            System.out.println("insertSealP.toString() = " + insertSealP.toString());

            stringRedisTemplate.delete("tDealParticulars");
            System.out.println(context.getTrigger().getKey().getName()+"  ");
        }else{
            System.out.println("无延期转账");
        }

    }
}
